# -*- coding: utf-8 -*-
# filename: menu.py
import json
import sys
import urllib2

from bbgkh.bbg_basic import BBG_Basic

reload(sys)
sys.setdefaultencoding('utf-8')


class Menu(object):
    def set(self, accessToken, menuCon):
        postUrl = " https://api.weixin.qq.com/cgi-bin/menu/create?access_token=%s" % (accessToken)
        menuCon = json.dumps(menuCon, ensure_ascii=False)
        print menuCon
        req = urllib2.Request(postUrl)
        req.add_header('Content-Type', 'application/json')
        req.add_header('encoding', 'utf-8')
        urlResp = urllib2.urlopen(req, menuCon)
        urlRespJson = json.loads(urlResp.read())
        print "调用自定义接口的返回值为：", urlRespJson['errcode'], urlRespJson['errmsg']
if __name__ == '__main__':
    myMenu = Menu()
    accessToken = BBG_Basic().get_access_token()
    buttons = {
            "button": [
                {
                    "type": "view",
                    "name": "在线商城",
                    "url": "http://www.bbgkh.shop/"
                },
                {
                    "type": "view",
                    "name": "我的会员",
                    "url": "http://m.admin.bbgkh.shop/member/myMemberPage"
                }
            ]
        }

    myMenu.set(accessToken, buttons)